let isRunning = {}
//显示系统运行环境
function getService(){
    asyncGet('/service/getDirConfig',null,null,function (res) {
        let all = res.tomcat.concat(res.nginx).concat(res.other)
        if (all.length > 0){
            let serverList = $('#server_list')
            serverList.html('')
            all.sort(function (a, b) { return a.name.localeCompare(b.name) });
            for (let i = 0; i < all.length; i++) {
                if (all[i].type === 'nginx' || all[i].type === 'tomcat' ){
                    serverList.append(`
                    <li style="height: 35px;">
                        <i class="layui-icon layui-icon-circle-dot" style="color: ${all[i].isAlive ? '#00c104' : '#bb001c'};display: inline-block"></i>
                        <p style="display: inline-block"><a href="javascript:;" onclick="parent.innerDir('${all[i].name}','${all[i].type}')">${all[i].name}</a></p>
                        <button onclick="startServer('${all[i].name}','${all[i].type}', this)"  ${(all[i].isAlive)  ? 'disabled' : '' }  style="display: inline-block;float: right;margin: 0 5px 0 5px" type="button" class="layui-btn layui-btn-xs layui-btn-normal ${(all[i].isAlive) || isRunning[all[i].name] ? 'layui-btn-disabled' : ''}">启动服务</button>
                    </li>
                    <hr class="layui-border-black">
                `)
                }else{
                    serverList.append(`
                    <li style="height: 35px;">
                        <i class="layui-icon layui-icon-layer" style="color: #f9d877;display: inline-block"></i>
                        <p style="display: inline-block"><a href="javascript:;" onclick="parent.innerDir('${all[i].name}','${all[i].type}')">${all[i].name}</a></p>
                        <button onclick="parent.innerDir('${all[i].name}','${all[i].type}')" style="display: inline-block;float: right;margin: 0 5px 0 5px" type="button" class="layui-btn layui-btn-xs layui-btn-normal ">打开位置</button>
                    </li>
                    <hr class="layui-border-black">
                `)
                }
            }
        }
        setTimeout('getService()',500);
    })
}

function startServer(name,type, self){
    isRunning[name] = true
    $(self).attr('disabled','').addClass('layui-btn-disabled')
    parent.startService(name,type)
}

getService()